package core.september.cloudbadge.model.user;

import javax.persistence.Embedded;
import javax.persistence.Id;

import core.september.cloudbadge.model.badge.AbsField.FieldType;
import core.september.cloudbadge.model.badge.BaseField;
import core.september.cloudbadge.model.badge.UserField;
import ezvcard.VCard;

public class UserModel {

	@Id
	private Long id;
	
	@Embedded
	private UserField uf;
	
	@Embedded
	private BaseField wf;
	
	@Embedded
	private BaseField hf;
	
	private Template template;
	
	public UserField getUf() {
		return uf;
	}

	public BaseField getWf() {
		return wf;
	}

	public BaseField getHf() {
		return hf;
	}
	
	public void setVcard(VCard vcard) {
		uf.setVcard(vcard);
		wf.setVcard(uf.getVcard());
		hf.setVcard(uf.getVcard());
	}
	
	

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}

	public UserModel() {
		uf = new UserField();
		
		wf = new BaseField();
		wf.setfType(FieldType.WORK);
		wf.setVcard(uf.getVcard());
		
		hf = new BaseField();
		hf.setfType(FieldType.HOME);
		hf.setVcard(uf.getVcard());
		//BaseField<String> workInfo = new BaseField<String>();
		
	}
	
	public void commit() {
		uf.commit();
		wf.commit();
		if(uf.hasHomeField()) {
			hf.commit();
		}
		
	}
	
}
